package com.itheima.tanhua.controller;

import com.itheima.tanhua.service.UserFreezeService;
import com.itheima.tanhua.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Lff
 * @date 2022/3/22
 */
@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;



    /**
     * 用户获取验证码
     *
     * @param map
     * @return
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map) {
        String phone = map.get("phone").toString();
        userService.sendMsg(phone);
        //响应数据
        return ResponseEntity.ok(null);
    }

    /**
     * 用户登录---验证码校验
     * /user/loginVerification
     *
     * @param map
     * @return
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map) {
        //获取请求参数
        String phone = map.get("phone").toString();
        String verificationCode = map.get("verificationCode").toString();
        //调用userService完成登录校验
        Map resultMap = userService.loginVerification(phone, verificationCode);
        //返回结果数据
        return ResponseEntity.ok(resultMap);

    }

}
